<template>
	<view>
		<view class="app">
			<u-toast ref="uToast"/>
			<view class="header">
				<u-image width="200rpx" height="200rpx" shape="circle" mode="widthFix" :src="appData.app_img"></u-image>
				<view>
					<view>{{appData.app_name}}</view>
					<view class="text">评分：<u-rate :count="5" v-model="appData.app_score" active-color="rgb(247, 186, 42)"></u-rate></view>
					<view>大小：{{appData.app_size}}MB</view>
				</view>
				<view >
					<u-button shape="square" type="primary" size="mini" @click="pushApp()">推送到平板端</u-button>
					<view style="margin-top: 20rpx;">
						<u-button shape="square" type="success" size="mini" @click="installApp()">安装到平板端</u-button>
					</view>
				</view>
			</view>
			<view class="body">
				<text style="font-weight: bold;">详情</text>
				<view class="preview">
					<u-image shape="circle" mode="widthFix" :src="appData.app_preview1">
						<view slot="error" style="font-size: 24rpx;">加载失败</view>
					</u-image>
					<u-image shape="circle" mode="widthFix" :src="appData.app_preview2">
						<view slot="error" style="font-size: 24rpx;">加载失败</view>
					</u-image>
					<u-image shape="circle" mode="widthFix" :src="appData.app_preview3">
						<view slot="error" style="font-size: 24rpx;">加载失败</view>
					</u-image>
				</view>
			</view>
			<view class="footer">
				<text style="font-weight: bold;">介绍</text>
				<view>{{appData.app_desc}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getAppDetails,
		appPush,
		appInstall
	} from '@/api/application.js'
import { installAppControl, pushAppControl } from '../../api/userHome'
	export default {
		data() {
			return {
				appData: {
					app_img: '',
					app_size: 0,
					app_downloads: 0,
					app_score: 1,
					app_remarks: '',
					app_preview1: '',
					app_preview2: '',
					app_preview3: ''
				},
				appId: undefined
			}
		},
		onLoad(option) {
			this.appId = option.appId
			this.AdminAppDetails(this.appId)
		},
		methods: {
			AdminAppDetails(appId) {
				getAppDetails({
					app_id: appId
				}).then(res => {
					this.appData = res.data
				}).catch(err => {
					this.appData = {}
				})
			},
			
			pushApp() {
				let param = {
					id: uni.getStorageSync('snId'),
					userId: uni.getStorageSync('userId'),
					lastIp: uni.getStorageSync('Ip'),
					app_id: this.appId
				}
				pushAppControl(param).then(res => {
					this.$refs.uToast.show({
						title: res.msg,
						type: 'success',
						icon: false
					})
				}).catch(err => {
					this.$refs.uToast.show({
						title: err.msg,
						type: 'error',
						icon: false
					})
				})
			},
			installApp() {
				let param = {
					id: uni.getStorageSync('snId'),
					userId: uni.getStorageSync('userId'),
					lastIp: uni.getStorageSync('Ip'),
					app_id: this.appId
				}
				installAppControl(param).then(res => {
					this.$refs.uToast.show({
						title: res.msg,
						type: 'success',
						icon: false
					})
				}).catch(err => {
					this.$refs.uToast.show({
						title: err.msg,
						type: 'error',
						icon: false
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.app {
		background-color: #ffffff;
		border-style: solid;
		border-color: #ffffff;
		border-radius: 20rpx;
		.header {
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
		.preview {
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
	}
</style>
